import { UiButton } from "@/shared/Uikit";
import { IFile, ILesson } from "@/shared/interfaces";
import { useEffect } from "react";
import { useUploadImage } from "../../editImageBlock/model/useUploadImageFile";
import { Input } from "antd";

type UploadImageFileProps = {
    onSuccess?: (res: IFile) => void,
}


export default function UploadImageFileForm(props: UploadImageFileProps) {
    const { handleSubmit, register, isSuccess, isError, isPending, response } = useUploadImage()

    useEffect(() => {
        console.log(response)
        if (isSuccess && response && props.onSuccess) {
            props.onSuccess(response)
        }
    }, [isSuccess])

    return (
        <div >
            <form onSubmit={handleSubmit}>
                <input type="file"{...register('file', { required: true })} />
                <label htmlFor="input-file" />
                <UiButton variant="primary">Upload file</UiButton>
            </form>
            {isSuccess && <>Успешно</>}
            {isError && <p>Ошибка</p>}
            {isPending && <>Загрузка...</>}
        </div>
    )
}